package net.sk.china.city.controller;

import net.sk.china.city.domain.ArInventory;
import net.sk.china.city.domain.vo.AddInventoryVO;
import net.sk.china.city.domain.vo.ArInventoryVO;
import net.sk.china.city.service.IArInventoryService;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.dto.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品库存Controller
 * 
 * @author gxf
 * @date 2024-04-29
 */
@Api(tags = "出入库管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/supermarket/inventory")
public class ArInventoryController extends BaseController
{
    @Autowired
    private IArInventoryService arInventoryService;

    /**
     * 查询商品库存列表
     */
    @ApiOperation("查询商品库存列表")
//    @PreAuthorize("@ss.hasPermi('supermarket:inventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArInventory arInventory)
    {
        startPage();
        List<ArInventoryVO> list = arInventoryService.selectArInventoryList(arInventory);
        return getDataTable(list);
    }

//    /**
//     * 导出商品库存列表
//     */
//    @PreAuthorize("@ss.hasPermi('supermarket:inventory:export')")
//    @Log(title = "商品库存", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ArInventory arInventory)
//    {
//        List<ArInventory> list = arInventoryService.selectArInventoryList(arInventory);
//        ExcelUtil<ArInventory> util = new ExcelUtil<ArInventory>(ArInventory.class);
//        util.exportExcel(response, list, "商品库存数据");
//    }

    /**
     * 获取商品库存详细信息
     */
//    @PreAuthorize("@ss.hasPermi('supermarket:inventory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(arInventoryService.selectArInventoryById(id));
    }

    /**
     * 新增商品库存
     */
//    @PreAuthorize("@ss.hasPermi('supermarket:inventory:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ArInventory arInventory)
    {
        return toAjax(arInventoryService.insertArInventory(arInventory));
    }

    /**
     * 修改商品库存
     */
//    @PreAuthorize("@ss.hasPermi('supermarket:inventory:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ArInventory arInventory)
    {
        return toAjax(arInventoryService.updateArInventory(arInventory));
    }

    /**
     * 删除商品库存
     */
//    @PreAuthorize("@ss.hasPermi('supermarket:inventory:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(arInventoryService.deleteArInventoryByIds(ids));
    }

    /**
     * 新增入库
     */
    @ApiOperation("入库")
    @PostMapping("/addInventory")
    public AjaxResult addInventory(@RequestBody AddInventoryVO addInventoryVO)
    {
        return success(arInventoryService.addArInventory(addInventoryVO));
    }

    /**
     * 新增出库
     */
    @ApiOperation("出库")
    @PostMapping("/outInventory")
    public AjaxResult outInventory(@RequestBody ArInventory arInventory)
    {
        return success(arInventoryService.outArInventory(arInventory));
    }

    @ApiOperation("根据入库商品编码查询入库商品信息")
    @GetMapping("/addInventory")
    public AjaxResult getAddInventory(@RequestParam("proCode")String proCode){
        return success(arInventoryService.getAddArInventory(proCode));
    }
}
